package ch07;

import java.util.*;

public class StudentMain {
    public static void main(String[] args) {
        LinkedList<Student> list = new LinkedList<Student>();
        list.add(new Student(1,"刘备",28));
        list.add(new Student(2,"关羽",27));
        list.add(new Student(3,"张飞",25));
        list.add(2,new Student(4,"赵云",24));
        list.addFirst(new Student(5,"曹操",38));// addFirst() removeFirst() getFirst() 都是子类的特有方法
        list.addLast(new Student(6,"孙权",21));//
        System.out.println(list.size());
        System.out.println(list);
//        list.remove(1);
//        list.removeFirst();
//        list.clear();
//        System.out.println(list.getFirst());
//        for (int i = 0; i < list.size(); i++) {
//            System.out.println(list.get(i));
//        }
        for (Student stu:list) {
            System.out.println(stu);
        }

        list.add(2,new Student(8,"诸葛亮",24));
//        list.remove(1);
//        list.set(1,new Student(8,"诸葛亮",24));
//        Iterator<Student> iterator = list.iterator();
//        while(iterator.hasNext()){
//            System.out.println(iterator.next());
//        }

        for(Iterator<Student> iterator = list.iterator();iterator.hasNext();){
            System.out.println(iterator.next());
        }
    }
}
